package com.tanhua.server.controller;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/24 0024 下午 3:58
 */

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.model.dto.SettingsDto;
import com.tanhua.model.dto.UserDto;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通用设置类接口
 */
@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    /**
     * 查询用户通用设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String) map.get("content");

        settingsService.saveQuestions(content);

        return ResponseEntity.ok(null);
    }

    /**
     * 通知管理：对通知进行保存或者更新的操作
     * @param settingsDto
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody SettingsDto settingsDto) {
        settingsService.saveSettings(settingsDto);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询黑名单列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size){
        PageResult pageResult = settingsService.blacklist(page,size);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 移除黑名单
     * @param blackUserId
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId){
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改手机号- 1 发送短信验证码
     * @return
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        settingsService.sendVerificationCode();

        return ResponseEntity.ok(null);
    }

    /**
     * 修改手机号 - 2 校验验证码
     * @param userDto
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody UserDto userDto){
        String verificationCode = userDto.getVerificationCode();

        Map map = settingsService.checkVerificationCode(verificationCode);

        return ResponseEntity.ok(map);
    }

    /**
     * 修改手机号 - 3 保存
     * @param userDto
     * @return
     */
    @PostMapping("/phone")
    public ResponseEntity updatePhone(@RequestBody UserDto userDto){
        String phone = userDto.getPhone();
        settingsService.updatePhone(phone);
        return ResponseEntity.ok(null);
    }
}
